﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OgilvyOne.BLL;


public partial class ExamplePage : System.Web.UI.Page
{
    /// <summary>
    /// where 字句属性
    /// </summary>
    private string sWhere
    {
        get { return (string) this.ViewState["sWhere"]; }
        set { this.ViewState.Add("sWhere", value); }
    }

    /// <summary>
    /// 排序字句属性
    /// </summary>
    private string sOrder
    {
        get { return (string) this.ViewState["sOrder"]; }
        set { this.ViewState.Add("sOrder", value); }
    }

    /// <summary>
    /// 查询时间段的起始时间
    /// </summary>
    protected string StartTime
    {
        get { return (string) this.ViewState["StartTime"]; }
        set { this.ViewState["StartTime"] = value; }
    }

    /// <summary>
    /// 查询时间段的终止时间
    /// </summary>
    protected string EndTime
    {
        get { return (string) this.ViewState["EndTime"]; }
        set { this.ViewState["EndTime"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.tbx_StartDate.Text = this.StartTime = DateTime.Today.ToShortDateString() + " 00:00:00";
            this.tbx_EndDate.Text = this.EndTime = DateTime.Today.ToShortDateString() + " 23:59:59";
            if (string.IsNullOrEmpty(this.sWhere))
                this.sWhere = "  begintime between '" + this.StartTime + "' and '" + this.EndTime + "'";
            if (string.IsNullOrEmpty(this.sOrder))
                this.sOrder = " begintime desc";
            this.BindData();
        }
    }

    private void BindData()
    { 
        
        int pageCount = 0;
        int rowCount = 0;
        Example bll = new Example();
       
        
        DataTable dt= bll.GetList(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, this.sWhere, this.sOrder,
                    out pageCount,
                    out rowCount);

            this.AspNetPager1.RecordCount = rowCount;
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();
     }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        this.BindData();
    }
    void delete()
    {
        //alert('dn');
        this.BindData();

    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        this.sOrder = Common.GetSortInfo(this.GridView1, e);
        this.BindData();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
       
        int sex = Convert.ToInt32(this.ddlSearchType.SelectedValue);
        string sKeyword = this.txbUserName.Text;
        this.sWhere = "sex=" + sex;
        if(sKeyword.Length>0)
        {
            this.sWhere += " AND username='" + sKeyword + "'";

        }
        string stdate = this.tbx_StartDate.Text;
        string endate = this.tbx_EndDate.Text;
        this.StartTime = string.IsNullOrEmpty(stdate) ? DateTime.Today.ToShortDateString() + " 00:00:00" : stdate;
        this.EndTime = string.IsNullOrEmpty(endate) ? DateTime.Today.ToShortDateString() + " 23:59:59" : endate;
        this.sWhere += " and begintime between '" + this.StartTime + "' and '" + this.EndTime + "'";
        this.BindData();

    }




}